package com.xyh.student.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyh.student.dao.LibraryDao;
import com.xyh.student.dao.QuestionDao;
import com.xyh.student.entity.Library;
import com.xyh.student.entity.Question;
import com.xyh.student.entity.ResponseData;
import com.xyh.student.service.LibraryService;

@Service("libraryService")
public class LibraryServiceImpl implements LibraryService {

    @Autowired
    private LibraryDao libraryDao;

    @Autowired
    private QuestionDao questionDao;

    @Override
    public ResponseData insertLibrary(Library library) {
        try {
            libraryDao.insertLibrary(library);
            return new ResponseData("0", "请求成功", library);
        } catch (Exception e) {
            System.out.println(e);
            return new ResponseData("888", "请求失败");
        }
    }

    @Override
    public ResponseData findAllLibrary() {
        try {
            List<Library> librarys = libraryDao.findAll();
            return new ResponseData("0", "请求成功",librarys);
        } catch (Exception e) {
            System.out.println(e);
            return new ResponseData("888", "请求失败");
        }
    }

    @Override
    public ResponseData findQuestion(int lid) {
        try {
            List<Question> questions = questionDao.findQuestionByLid(lid);
            return new ResponseData("0", "请求成功",questions);
        } catch (Exception e) {
            return new ResponseData("888", "请求失败");
        }
    }

    @Override
    public ResponseData findById(int id) {
        try {
            Library library = libraryDao.findById(id);
            return new ResponseData("0", "请求成功",library);
        } catch (Exception e) {
            return new ResponseData("888", "请求失败");
        }
    }

    @Override
    public ResponseData deleteById(int id) {
        try {
            libraryDao.deleteById(id);
            return new ResponseData("0", "删除成功");
        } catch (Exception e) {
            return new ResponseData("888", "删除失败");
        }
    }

}
